<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>资讯中心</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>

    <script type="text/javascript">
        function closeWin() {
            api.closeWin({});
        };
    </script>
</head>

<body>
    <!-- 头部 -->
    <div id="list">
    </div>
</body>


<script type='text/template' id='template'>
    {{~it :value:index}}
    <div class="news-list">
        <ul>
            <li tapmode onclick="news_detail({{=value.id}})">
                <dl>
                    <!-- <dt>http://app.big-wealth.com{{=value.icon}}</dt> -->
                    <dt>{{=value.title}}</dt>
                    <dd>{{=value.description}}</dd>
                </dl>
                <p>{{=value.update_time}}</p>
            </li>
        </ul>
    </div>
    {{~}}
</script>


<script type="text/javascript">
    // 资讯详情
    function news_detail(n) {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }

        // alert(n);
        api.openWin({
            name: 'news-detail',
            url: './news-detail.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            pageParam: {
                id: n
            }
        });
    };

    apiready = function() {

        fnGetNewData();
        down_refresh();
        addObserver();

    };
    //刷新


    //数据请求
    function fnGetNewData(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        if (n) {
            page += 1;
        } else {
            page = 1;
        }

        api.ajax({
            url: webAddress + '/index.php?ctl=app_article&act=article_list',
            method: 'post',
            data: {
                values: {
                    cate_id: api.pageParam.id,
                    page: page
                },
            }
        }, function(ret, err) {
            if (ret) {
                var data = ret.list;
                upDataNew(data, page);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });
    }

    function upDataNew(data, n) {



        // alert(data);
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');

        if (n == 1) {
            $api.html(list, html);
        } else {
            if (data == '') {

                // alert(1);
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }

            $api.append(list, html);
        }

        api.parseTapmode();
    }

    //上拉刷新监听
    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {
            fnGetNewData(true);
        });
    }


    // 下拉刷新
    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            fnGetNewData();
        });
    }
</script>

</html>
